// pages/payfor/settlement.js
import { httpPost } from '../common/HttpBean.js'
let thisa;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goodlist: {},
    count: 0,
    tablenum: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    thisa = this;
    thisa.showBuyCar();
  },
  showBuyCar: function (e) {
    let str = wx.getStorageSync('shoppingcar');
    let json = JSON.parse(str);
    let len = json.length;
    let sum = 0;
    for (let key in json) {
      sum += json[key][1] * json[key][2];
    }
    // if (thisa.data.buycarShow){
    thisa.setData({
      // buycarShow: false,
      goodsList: json,
      count: sum
    });
    // }else{
    //   thisa.setData({
    //     buycarShow: true
    //   });
    // }
  },
  setTablenum: function (e) {
    console.log(e.detail.value);
    thisa.setData({
      tablenum: e.detail.value
    });
  },
  subpay: function () {
    l
  },
  subpay: function () {
    let tablenum = thisa.data.tablenum;
    // let goodlist = wx.getStorageSync('shoppingcar')
    // console.log(goodlist);
    let shopID = wx.getStorageSync('shopID')
    let count = thisa.data.count
    if (tablenum != '') {
      let url = '/addOrder'
      //支付
      let data = { goodlist: wx.getStorageSync('shoppingcar'), tablenum: tablenum, shopID: shopID,count:count}
      console.log('------------')
      console.log(data)
      //提交数据
      function sucFun(res) {
        let  redata = res.data
        if (redata == 1){
          wx.showModal({
            title: '订单已提交',
            showCancel :false,
            content:'请等待上菜',
            success:function(res){
              wx.navigateTo({
                url: '/pages/main/main',
              });
              
            }
          })
        }
      }
      function failFun(res) {
        console.log('err:' + ':' + res);
      }
      httpPost(url, data, sucFun, failFun);
    } else {
      wx.showModal({
        title: '提示',
        content: '请填写桌号',
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})